|
1
|
|
|
import {expect} from 'chai'; |
|
2
|
|
|
import store from '../../src/model/store'; |
|
3
|
|
|
|
|
4
|
|
|
describe('store reset', () => { |
|
5
|
|
|
it('should empty the store', () => { |
|
6
|
|
|
store._store = { |
|
7
|
|
|
'foo': 'bar' |
|
8
|
|
|
}; |
|
9
|
|
|
store.reset(); |
|
10
|
|
|
expect(store._store).not.to.have.property('foo'); |
|
11
|
|
|
}); |
|
12
|
|
|
}); |
|
13
|
|
|
|
|
14
|
|
|
describe('store set', () => { |
|
15
|
|
|
beforeEach(() => { |
|
16
|
|
|
store.reset(); |
|
17
|
|
|
}); |
|
18
|
|
|
|
|
19
|
|
|
it('should be able to set a key/value', () => { |
|
20
|
|
|
store.set('foo', 'bar'); |
|
21
|
|
|
expect(store._store).to.have.property('foo', 'bar'); |
|
22
|
|
|
}); |
|
23
|
|
|
|
|
24
|
|
|
it('should be able to set a multi level key', () => { |
|
25
|
|
|
store.set('foo.bar', 42); |
|
26
|
|
|
expect(store._store).to.have.property('foo'); |
|
27
|
|
|
expect(store._store.foo).to.have.property('bar', 42); |
|
28
|
|
|
}); |
|
29
|
|
|
|
|
30
|
|
|
it('should be able to set a multi level key', () => { |
|
31
|
|
|
store.set('foo.bar.deep', 42); |
|
32
|
|
|
expect(store._store).to.have.property('foo'); |
|
33
|
|
|
expect(store._store.foo).to.have.property('bar'); |
|
34
|
|
|
expect(store._store.foo.bar).to.have.property('deep', 42); |
|
35
|
|
|
}); |
|
36
|
|
|
|
|
37
|
|
|
it('should be able to set multiple multi level key', () => { |
|
38
|
|
|
store.set('foo.bar.deep', 42); |
|
39
|
|
|
store.set('foo.baz.deep', 43); |
|
40
|
|
|
expect(store._store).to.have.property('foo'); |
|
41
|
|
|
expect(store._store.foo).to.have.property('bar'); |
|
42
|
|
|
expect(store._store.foo).to.have.property('baz'); |
|
43
|
|
|
expect(store._store.foo.bar).to.have.property('deep', 42); |
|
44
|
|
|
expect(store._store.foo.baz).to.have.property('deep', 43); |
|
45
|
|
|
}); |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
describe('store get', () => { |
|
50
|
|
|
|
|
51
|
|
|
beforeEach(() => { |
|
52
|
|
|
store.reset(); |
|
53
|
|
|
store._store = { |
|
54
|
|
|
'foo': { |
|
55
|
|
|
'bar': { |
|
56
|
|
|
'baz': 42 |
|
57
|
|
|
} |
|
58
|
|
|
}, |
|
59
|
|
|
'foobar': 'raboof', |
|
60
|
|
|
'foobaz': 'zaboof' |
|
61
|
|
|
}; |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
it('should be able to recover a value from the store', () => { |
|
66
|
|
|
expect(store.get('foobar')).to.equal('raboof'); |
|
67
|
|
|
}); |
|
68
|
|
|
|
|
69
|
|
|
it('should be able to read a multi level key from the store', () => { |
|
70
|
|
|
let value = store.get('foo.bar'); |
|
71
|
|
|
expect(value).to.have.property('baz', 42); |
|
72
|
|
|
}); |
|
73
|
|
|
|
|
74
|
|
|
it('should be able to read a multi level key from the store', () => { |
|
75
|
|
|
expect(store.get('foo.bar.baz')).to.equal(42); |
|
76
|
|
|
}); |
|
77
|
|
|
|
|
78
|
|
|
it('should return the whole store if no key is given', () => { |
|
79
|
|
|
let value = store.get(); |
|
80
|
|
|
expect(value).to.have.property('foobar', 'raboof'); |
|
81
|
|
|
expect(value).to.have.property('foobaz', 'zaboof'); |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
it('should return the default value if the key is undefined', () => { |
|
85
|
|
|
expect(store.get('unknown', 42)).to.equal(42); |
|
86
|
|
|
}); |
|
87
|
|
|
}); |
|
88
|
|
|
|